<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>仪表盘</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.1/font/bootstrap-icons.css">
    <style>
        body {
            background-color: #f8f9fa;
            padding: 20px;
        }
        .card {
            margin-bottom: 20px;
            border-radius: 10px;
            box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
            transition: transform 0.3s, box-shadow 0.3s;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
        }
        .card-icon {
            font-size: 2.5rem;
            margin-bottom: 15px;
        }
        .chart-container {
            height: 300px;
        }
    </style>
</head>
<body>
    <h4 class="mb-4">仪表盘</h4>
    
    <div class="row">
        <!-- 统计卡片 -->
        <div class="col-md-3">
            <div class="card text-center p-4">
                <div class="card-icon text-primary">
                    <i class="bi bi-people"></i>
                </div>
                <h3 id="userCount">0</h3>
                <p class="text-muted">用户总数</p>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card text-center p-4">
                <div class="card-icon text-success">
                    <i class="bi bi-check-circle"></i>
                </div>
                <h3 id="activeUserCount">0</h3>
                <p class="text-muted">活跃用户</p>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card text-center p-4">
                <div class="card-icon text-info">
                    <i class="bi bi-list-check"></i>
                </div>
                <h3 id="menuCount">0</h3>
                <p class="text-muted">菜单总数</p>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card text-center p-4">
                <div class="card-icon text-warning">
                    <i class="bi bi-gear"></i>
                </div>
                <h3 id="systemCount">1</h3>
                <p class="text-muted">系统总数</p>
            </div>
        </div>
    </div>
    
    <div class="row mt-4">
        <!-- 图表 -->
        <div class="col-md-6">
            <div class="card p-3">
                <h5>用户增长趋势</h5>
                <div class="chart-container" id="userGrowthChart">
                    <div class="d-flex justify-content-center align-items-center h-100">
                        <p class="text-muted">加载中...</p>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="card p-3">
                <h5>活跃度分析</h5>
                <div class="chart-container" id="activeAnalysisChart">
                    <div class="d-flex justify-content-center align-items-center h-100">
                        <p class="text-muted">加载中...</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
    <script>
        $(document).ready(function() {
            // 加载统计数据
            loadStats();
            
            // 每30秒刷新一次数据
            setInterval(loadStats, 30000);
        });
        
        function loadStats() {
            // 获取统计数据
            $.ajax({
                url: '/admin/api/stats',
                type: 'GET',
                headers: {
                    'Authorization': 'Bearer ' + localStorage.getItem('token')
                },
                success: function(response) {
                    // 更新统计卡片
                    $('#userCount').text(response.user_count || 0);
                    $('#activeUserCount').text(response.active_user_count || 0);
                    $('#menuCount').text(response.menu_count || 0);
                    
                    // 这里可以添加图表绘制代码
                    drawCharts(response);
                },
                error: function(xhr) {
                    console.error('加载统计数据失败', xhr);
                }
            });
        }
        
        function drawCharts(data) {
            // 这里是图表绘制代码的占位符
            // 实际项目中可以使用Chart.js或其他图表库
            $('#userGrowthChart').html(`
                <div class="d-flex justify-content-center align-items-center h-100">
                    <p>用户增长趋势图表（示例）</p>
                </div>
            `);
            
            $('#activeAnalysisChart').html(`
                <div class="d-flex justify-content-center align-items-center h-100">
                    <p>活跃度分析图表（示例）</p>
                </div>
            `);
        }
    </script>
</body>
</html> 